<template>
  <!-- 服务站财务数据查询 -->
  <div>
    <TopFilter :list="financialTopFilterList" :cols="4" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <FilterTable
      ref="table"
      columnsRef="waxFinancialformA"
      :isSelectColumn="false"
      :isMemoryPagination="true"
      :columns="columns"
      :datakey="'rows'"
      :onColumnsChange="columns => (this.columns = columns)"
      :dataSource="dataSource"
      :isExportExcel="true"
      exportFileName="服务站财务数据查询.xlsx"
    >
      <!-- :fetchapi="fetchApi"
      :params="fetchParams" -->
      <!-- :fetchapi="fetchApi" -->
      <template slot="controls" slot-scope="props">
        <!-- <el-button size="small" type="primary" icon="el-icon-plus" @click="publishInfo">新建</el-button>
        <AjaxButton :click="pushDialog" type="primary">发布</AjaxButton>
        <AjaxButton :click="offlineDialog" type="primary">下线</AjaxButton> -->
      </template>
    </FilterTable>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { getFinanceList } from '@/api/part/report/financialQuery';
import moment from 'moment';
export default {
  name: 'FinancialQuery',
  components: {},
  mixins: [dictionary],
  props: [],
  data() {
    return {
      financialTopFilterList: this.createFinancialTopFilterList(),
      columns: this.createTableList(),
      fetchParams: { xhrAbort: true },
      fetchApi: getFinanceList,
      dataSource: []
    };
  },
  methods: {
    // 展开收起调用函数
    collapseHandle() {},
    // 搜索条件改变调用方法
    async changeHandle(val) {
      // this.fetchParams.xhrAbort = true;
      // this.fetchParams = Object.assign(this.fetchParams, { xhrAbort: false }, { ImportParameter: val });
      let res = await getFinanceList(Object.assign(this.fetchParams, { xhrAbort: false }, { ImportParameter: val }));
      this.dataSource = [];
      this.dataSource = res.data;
      // this.columns = [...this.columns];
    },
    // 创建表单字段列表
    createTableList() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '财政',
          dataIndex: 'GJAHR',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '周期',
          dataIndex: 'LFMON',
          sorter: true,
          filter: true,
          filterType: 'input',
          summation: true,
          summationDataIndex: 'SUM1'
        },
        {
          title: '期初余额',
          dataIndex: 'UMSAV',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2,
          summation: true,
          summationDataIndex: 'SUM2'
        },
        {
          title: '本期应收',
          dataIndex: 'UMDTS',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2,
          summation: true,
          summationDataIndex: 'SUM3'
        },
        {
          title: '本期来款',
          dataIndex: 'UMCTH',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2,
          summation: true,
          summationDataIndex: 'SUM4'
        },
        {
          title: '期末余额',
          dataIndex: 'UMHAV',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2,
          summation: true,
          summationDataIndex: 'SUM5'
        },
        {
          title: '信贷额度',
          dataIndex: 'KLIMK',
          sorter: true,
          filter: true,
          filterType: 'input',
          precision: 2,
          summation: true,
          summationDataIndex: 'SUM6'
        },
        {
          title: '发出数量',
          dataIndex: 'FKIMG',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2,
          summation: true,
          summationDataIndex: 'SUM7'
        }
      ];
    },
    // 创建筛选条件
    createFinancialTopFilterList() {
      return [
        {
          type: 'INPUT_NUMBER',
          label: '财政年',
          fieldName: 'I_GJAHR',
          placeholder: '',
          initialValue: moment().get('year'),
          rules: [
            { required: true, message: '请输入财政年', trigger: 'blur' },
            {
              validator: (rule, value, callback) => {
                let reg = /^(19|20)\d{2}$/;
                if (!reg.test(value)) {
                  callback(new Error('请输入正确财政年,例如:20xx'));
                } else {
                  callback();
                }
              },
              trigger: 'blur'
            }
          ]
        },
        {
          type: 'RANGE_INPUT_NUMBER',
          label: '财政月',
          fieldName: 'I_LFMON_S|I_LFMON_E',
          placeholder: '',
          initialValue: [1, 16],
          min: 1,
          max: 16,
          rules: [{ required: true, message: '请输入财政月', trigger: 'blur' }]
        },
        {
          type: 'SELECT',
          label: '查询类型',
          fieldName: 'I_TYPE',
          placeholder: '',
          itemList: [
            { text: '配件', value: 'BJ' },
            { text: '工服', value: 'GF' },
            { text: '精品', value: 'JP' },
            { text: '工具', value: 'GJ' }
          ]
        }
      ];
    }
  }
};
</script>

<style></style>
